package com.dongdong.service.impl;

import com.dongdong.mapper.TbItemCatMapper;
import com.dongdong.mapper.TbItemMapper;
import com.dongdong.pojo.*;
import com.dongdong.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemCatMapper tbItemCatMapper;

    @Autowired
    private TbItemMapper itemMapper;

    @Override
    public List<TbItemCat> selectAll() {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(0L);
        List<TbItemCat> itemCatList = tbItemCatMapper.selectByExample(example);
        return itemCatList;
    }

    @Override
    public List<TbItemCat> selectPid(Long id) {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(id);
        List<TbItemCat> itemCatList = tbItemCatMapper.selectByExample(example);
        return itemCatList;
    }

    @Override
    public boolean insert(TbItemCat itemCatc) {
        int i = tbItemCatMapper.insertSelective(itemCatc);
        return i > 0;
    }

    @Override
    public boolean delete(Long id) {
        int i = tbItemCatMapper.deleteByPrimaryKey(id);
        return i > 0;
    }

    @Override
    public TbItemCat selectId(Long id) {
        TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(id);
        return tbItemCat;
    }

    @Override
    public boolean update(TbItemCat tbItemCat) {
        int i = tbItemCatMapper.updateByPrimaryKey(tbItemCat);
        return i > 0;
    }


    @Override
    public List<TbItemCat> selectChlid(Long id) {
        TbItemCatExample example = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(id);
        List<TbItemCat> itemCatList = tbItemCatMapper.selectByExample(example);
        return itemCatList;
    }

    @Override
    public TbItemCat selectid(Long id) {
        TbItemCat tbItemCat = tbItemCatMapper.selectByPrimaryKey(id);
        return tbItemCat;
    }

    @Override
    public List<TbItem> selectIdAndStu(Long goodsId) {
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(goodsId);
        criteria.andStatusEqualTo("1");
        List<TbItem> items = itemMapper.selectByExample(example);
        return items;
    }


    @Override
    public TbItem selectById(Long itemId) {
        TbItem item = itemMapper.selectByPrimaryKey(itemId);
        return item;
    }
}
